﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using Yuekao.Domain.BaseReposi;
using Yuekao.Domain.Entitys;

namespace Yuekao.Domain.Step
{
    public class EndStep : StepBody
    {
        private readonly IBaseRepository<WorkflowInstanceModel> _baseRepository;
        public EndStep(IBaseRepository<WorkflowInstanceModel> repository)
        {
            _baseRepository = repository;
        }
        public override ExecutionResult Run(IStepExecutionContext context)
        {
            Console.WriteLine("步骤结束了");
            context.Workflow.Status = WorkflowStatus.Complete;

            // 使用同步方式处理异步操作
            var list = _baseRepository.GetValues(x => x.WorkflowId == context.Workflow.Id).Result;
            list.StepId = nameof(EndStep);
            list.StepName = "结束";
            list.AuditId = 0;
            list.AuditName = "";
            list.State = "审批通过";
            list.CompeltaTime = DateTime.Now;
            _baseRepository.Update(list);

            return ExecutionResult.Next();
        }
    }
}
